package com.wang.learn.common.aspect;

import com.wang.learn.common.exception.BizException;
import com.wang.learn.common.exception.SystemException;
import com.wang.learn.common.model.BaseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 类描述：
 * 全局异常处理器
 * @author Charles
 * @version 1.0.0
 * @time 2021/10/9
 */
@RestControllerAdvice
public class LearnExceptionHandler {

    private static Logger logger = LoggerFactory.getLogger(LearnExceptionHandler.class);

    /**
     * 业务异常的处理方法
     * @param e
     * @return
     */
    @ExceptionHandler(value=BizException.class)
    public BaseResult bizExceptionHandler(BizException e){
        return e.toResult();
    }

    /**
     * 系统异常的处理方法
     * @param e
     * @return
     */
    @ExceptionHandler(value = SystemException.class)
    public BaseResult sysException(SystemException e){
        return e.toResult();
    }
}
